package com.info33.platform.business.app.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.info33.platform.business.app.dao.AppAboutUsDao;
import com.info33.platform.business.app.entity.AppAboutUs;
import com.info33.platform.business.app.service.AppAboutUsService;
import com.info33.platform.common.mvc.vo.Result;
import com.info33.platform.common.util.SysUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author admin
 */
@Service
public class AppAboutUsServiceImpl extends ServiceImpl<AppAboutUsDao, AppAboutUs> implements AppAboutUsService {

    @Autowired
    private AppAboutUsDao aboutUsDao;

    @Override
    public Result<Object> pcUpdate(AppAboutUs entity) {
        AppAboutUs old = aboutUsDao.selectById(entity.getId());
        if (Boolean.TRUE.equals(old.getCommon())
                && Boolean.FALSE.equals(SysUtil.isSysAdmin())) {
            return Result.error(Result.RESULT_ERROR_NO_POWER);
        }
        return this.updateById(entity) ? Result.ok() : Result.error();
    }

    @Override
    public Result<Object> pcRemove(Long id) {
        AppAboutUs old = aboutUsDao.selectById(id);
        if (Boolean.TRUE.equals(old.getCommon())
                && Boolean.FALSE.equals(SysUtil.isSysAdmin())) {
            return Result.error(Result.RESULT_ERROR_NO_POWER);
        }
        return this.removeById(id) ? Result.ok() : Result.error();
    }

}